﻿/*
创建人：longb
日期：2022-07-13
描述：APS排产任务单选择js
*/
var page = {
    pagetotal: 0,
    pageSize: 20,
    pageNumber: 1,
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ZSLimitedCapacityHandler.ashx",
    //初始化页面
    init: function () {
        page.bind();
        customizedEasyuiPagination('pp'); //定制化分页
    },
    //页面事件绑定
    bind: function () {
        $('#OrderType').combobox({
            data: [{ id: 1, text: '正常' }, { id: 0, text: '临时'}],
            valueField: 'id',
            textField: 'text'
        });
        $('#BigSmall').combobox({
            data: [{ id: 0, text: '否' }, { id: 1, text: '是'}],
            valueField: 'id',
            textField: 'text'
        });
        $('#OrderType').combobox('setValue', 1);
        $('#BigSmall').combobox('setValue', 1);
        //任务单信息
        $("#gdContainerInfo").datagrid({
            //            checkOnSelect: false,
            //            selectOnCheck: false,
            //            singleSelect: true,
            rownumbers: true,
            onLoadSuccess: function (data) {
                $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
                customizedEasyuiPagination('pp'); //定制化分页
            },
            columns: [[
                 { field: 'ck', title: '选择', checkbox: true },
                 { field: 'ENGINENO', title: '发动机号', width: 120 },
                 { field: 'MFGORDERNAME', title: '订单号', width: 150 },
		         { field: 'CONTAINERNO', title: '任务单号', width: 180 },
		         { field: 'WORKFLOWTYPE', title: '任务类型', width: 80 }, //--
                 {field: 'PRODUCTNAME', title: '件号', width: 100 },
                 { field: 'PRODUCTDESCRIPTION', title: '件号名称', width: 90 },
                 { field: 'WFR', title: '工艺信息', width: 150 },
                 { field: 'WFDESC', title: '工艺名称', width: 120 },
                 { field: 'PLANNEDSTARTDATE', title: '计划开始时间', width: 130, formatter: function (value, row, index) {
                     if (value != null)
                         return dayjs(value).format("YYYY-MM-DD");
                 }
                 },
                 { field: 'PLANNEDFINISHDATE', title: '计划完成时间', width: 130, formatter: function (value, row, index) {
                     if (value != null)
                         return dayjs(value).format("YYYY-MM-DD");
                 }
                 },
                 { field: 'WORKFLOWSTEPNAME', title: '阶段', width: 100 },
                 { field: 'expectmaterialdate', title: '预计到料时间', width: 100, hidden: true }
	           ]]
        });
        //分页事件
        $('#pp').pagination({
            onSelectPage: function (pageNumber, pageSize) {
                customizedEasyuiPagination('pp'); //定制化分页
                page.pageSize = pageSize; page.pageNumber = pageNumber;
                page.GetTaskOrderData();
            }
        });
        //绑定分页go按钮
        $('#pageGo').on("click", function () {
            var pageNumber = $(this).parents('tr').find('.pagination-num').val();
            page.pageNumber = pageNumber;
            page.GetTaskOrderData();
        });
        //清除按钮
        $('#btnReset').on("click", function () {
            page.reset(true, true);            
        });
    },
    //查询
    searchData: function () {
        page.reset(false, true);
        page.pageNumber = 1;
        page.GetTaskOrderData();
    },
    //查询任务单信息
    GetTaskOrderData: function () {
        var frdata = $('#searchForm').serializeArray();
        var data = {};
        $.each(frdata, function () {
            data[this.name] = this.value
        });
        var param = {
            action: "GetZsApsOrderTask",
            IsPool: '0',
            pageSize: page.pageSize,
            pageNumber: page.pageNumber,
            data: JSON.stringify([data])
        };
        page.post(param, function (res) {
            if (res.Result) {
                //console.info(res);
                page.pagetotal = res.RowCount;
                $('#gdContainerInfo').datagrid('loadData', res.DBTable);
                parent.$("#orderSelect").dialog('options').returnData = res;
            }
        });
    },
    CloseDilog: function () { parent.$("#orderSelect").dialog('close'); },
    //查询重置
    searchReset: function () {
//        $('#searchForm').form('clear');
//        page.bind();
    },
    //
    AddOrderSelect: function (index) {
        var rows = $('#gdContainerInfo').datagrid('getChecked');
        if (rows.length == 0) {
            displayMessage("请先勾选任务单信息，再进行确认");
            return;
        }
        var param = {
            action: "AddOrderToApsPool",
            data: JSON.stringify(rows)
        };
        page.post(param, function (res) {
            if (res.Result) { page.GetTaskOrderData(); }
            displayMessage(res.Message, res.Result);
        });

    },
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
        if (iscondition) {
            $('#searchForm').form('clear');
        }

        if (isresult) {
            clearEasyuiDataGrid("gdContainerInfo", 1); //查询结果列表
            page.pageNumber = 1; page.pagetotal = 0
            $('#pp').pagination('refresh', {
                total: page.pagetotal,
                pageSize: page.pageSize,
                pageNumber: page.pageNumber
            });
        }
    },
    //post数据
    post: function (param, callback) {
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});